var app = getApp();
Component({
    behaviors: [],
    options: {
        multipleSlots: true
    },
    properties: {
        _type: String,
        _item: Object,
        _index:Number
    },
    data: {
        attentionState:0
    },
    methods: {
        handleAttention: function (e) {
            let self = this
            let url = app.globalData.url.interestManage;
            let cauthorid = e.currentTarget.dataset.id
            let userIds = app.globalData.userId;
            let attentionState = self.data.attentionState;
            if (attentionState == 1) {//取消关注
                self.Attention(url,cauthorid,0,userIds,'取消关注')
            }else{
               self.Attention(url,cauthorid,1,userIds,'关注成功')
            }
        },
        Attention:function(url,cauthorid,type,userIds,toast){
            var self = this
            if (!userIds) {
                wx.navigateTo({url:'../loginPhone/index'})
                return false
            }
            wx.request({
                  url: url,
                  data:{
                    author:cauthorid,
                    type:type, //0取消关注 1关注
                    userId:userIds
                  },
                  method: "GET",
                  success(res) {
                    let code = res.statusCode
                    if (code == '200') {
                      let data = res.data
                      if (data.status == '_0000') {
                            wx.showToast({
                                title:toast,
                                icon:'success'
                            });
                            self.setData({
                              attentionState:type
                            })
                        }
                    } else {
                      console.log(res.errMsg)
                    }
                  },
                  fail(res) {
                    console.log(res.statusCode)
                  }
                })
        }
    },
    attached: function() {
        this.setData({
          attentionState:this.data._item.fans
        })
     },

});